<?php
namespace Api;
use Kuyuan\WqCore\api\Api;
use Kuyuan\WqCore\util\Util;

/**
 * 上传接口
 * Class Share
 * @package Api
 */
class Upload extends Api
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 上传图片
     */
    public function image()
    {
        global $_W;
        try {
            load()->func('file');
            $_result = file_upload($_FILES["image"]);
            if(!isset($_result["success"]) || !$_result["success"]) {
                throw new \Exception("",600);
            }
            if($_W['setting']['remote']['type'] != 0) {
                file_remote_upload($_result["path"]);
            }
            Util::returns(array("code"=>0,"data"=>array("source"=>$_result["path"],"src"=>tomedia($_result["path"]))));
        }catch (\Exception $e) {
            Util::returns(array("code"=>$e->getCode()));
        }
    }
}